﻿using System;
using System.Collections.Specialized;
using Core.ApiMetods.Abstract;
using DomainModels.DomainModels.Systems;

namespace Core.Manager
{
    public class Manager : IManager
    {
        private IFactory _factory;

        public IFactory Factory {
            get { return _factory; }
        }

        private TokenResponse _token;

        public BaseMethod GetMethod(IFactory factory)
        {
            _factory = factory;
            if (_token == null)
            {
                throw  new ArgumentNullException();
            }

            return _factory.GetUserWorker(_token);
        }

        public TokenResponse GetToken()
        {
            return _token;
        }

        public void SetToken(NameValueCollection collection)
        {
            _token = new TokenResponse
            {
                AccessToken = collection.Get("access_token"),
                UserId = collection.Get("user_id"),
                ExpiresIn = collection.Get("expires_in")
            };
        }
    }
}